package com.browsesoft.htmlcomponent;

import org.w3c.dom.Element;
import org.w3c.dom.Text;

import com.browsesoft.ExtendElement;
import com.browsesoft.arrange.Arrange;

public class HTMLArrangeTreeComponent extends HTMLTreeComponent {
	/**
	 * 构造器
	 * 
	 * @param parent
	 *            组件的父组件
	 */
	public HTMLArrangeTreeComponent(HTMLBasicComponent parent) throws Exception {
		super(parent);
	}

	/**
	 * 设置内容节点属性
	 * 
	 * @param nodeLink
	 *            内容节点
	 * @param node
	 *            内容节点的父亲节点
	 * @param modelNode
	 *            对应的model
	 */
	protected void setContextNode(Element nodeLink, Element node,
			Object modelNode) throws Exception {
		if (((Arrange) modelNode).isRoot()) {
			Element e = this.getPage().getDocument().createElement("test");
			nodeLink.getParentNode().replaceChild(e, nodeLink);
			e.setAttribute("type", "nodelink");
			Text text = this.getPage().getDocument().createTextNode(
					((HTMLTreeModel) model).getName(modelNode));
			e.appendChild(text);
			nodeLink = e;
		} else {
			nodeLink.setAttribute("href", "#");
			String link = nodeLink.getAttribute("onclick");
			link = link.substring(0, link.indexOf("point=") + 6)
					+ ((HTMLTreeModel) model).getID(modelNode)
					+ link.substring(link.indexOf("point=") + 6, link.length());
			nodeLink.setAttribute("onclick", link);
		}
		// 设置节点文本
		Text name = this.getPage().getDocument().createTextNode(
				((HTMLTreeModel) model).getName(modelNode));
		ExtendElement.replaceElementContext(nodeLink, name);
	}
}